import java.util.Set;

public class CC12 {
    public boolean wordBreak(String s, Set<String> dict) {
        boolean[] canbreak = new boolean[s.length() + 1];
        canbreak[0] = true;//辅助操作
        for (int i = 1; i <= s.length(); i++) {
            for (int j = 0; j < i; j++) {
                if(canbreak[j] && dict.contains(s.substring(j,i))){
                    canbreak[i] = true;
                    break;
                }
            }
        }
        return canbreak[s.length()];
    }
}
